import pymysql

db = pymysql.connect(host='localhost', port=3306, user='root', passwd='123456', database='test_123', charset='utf8')
cur = db.cursor()
sql = "select * from Images \
      where filename = 'mysql.jpg'"
cur.execute(sql)
image = cur.fetchone()
# 默认在当前目录新建image[1]文件
with open(image[1], 'wb') as fd:
    fd.write(image[2])
cur.close()
db.close()
